import { mock } from "mockjs";
import { ExternalLinksSign } from "src/models/externalLinksSign";
import { DataList } from "src/business/models/user";

export let extern: ExternalLinksSign[] = [
    {
        id: "1",
        handle_code: "外链标识1",
        handle_name: "外链类名1",
        handle_type: "类型1",
        user_id: "1",
        rc_code: "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=3630050586,4001820935&fm=58",
        create_date: "2019-06-28",
        modify_date: "2019-06-28",
        link_website: "http://www.baidu.com",
        company_handle_name: "公司标名称1",
        company_handle_code: "公司标标识1"
    },
    {
        id: "2",
        handle_code: "外链标识2",
        handle_name: "外链类名2",
        handle_type: "类型2",
        user_id: "2",
        rc_code: "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=3630050586,4001820935&fm=58",
        create_date: "2019-06-28",
        modify_date: "2019-06-28",
        link_website: "http://www.baidu.com",
        company_handle_name: "公司标名称2",
        company_handle_code: "公司标标识1"
    },
];

export function get_external_link_list(info: ExternalLinksSign, page_num?: number, size?: number) {
    let tmp: ExternalLinksSign[] = [];
    for (const key in info) {
        if (info.hasOwnProperty(key)) {
            extern.map((e, i) =>
                e[key] === info[key] ? tmp.push(e) : null
            );
        }
    }

    let ret: DataList<ExternalLinksSign> = {};
    ret.total = extern.length;
    ret.result = extern;
    return mock({ result: ret });
}

export function delete_extern_link(ids: { id: string }[]) {
    for (const key in ids) {
        if (ids.hasOwnProperty(key)) {
            const element = ids[key];
            let index: number;
            extern.find((e, i) => {
                if (e.id === element.id) {
                    index = i;
                    return true;
                }
                return false;
            });
            extern.splice(index!, 1);
        }
    }
    return mock({ result: extern });
}

export function get_external_link(id: string) {
    let index: number;
    extern.find((e, i) => {
        if (e.id === id) {
            index = i;
            return true;
        }
        return false;
    });

    return mock({ result: extern[index!] });
}

// export function  get_single_list?(object?: Object, page_num?: number, num?: number){

// }